package cn.ljz.item.controller;

import cn.ljz.pojo.Item;
import cn.ljz.service.ItemService;
import cn.ljz.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title cloud-itemservice.ItemController
 * @Author LJZ
 * @Description: <TODO description class purpose>
 * @Create 2024/3/13 12:02
 * @Version 1.0
 **/
@Slf4j
@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;
    @Value("${server.port}")
    private int port;
    @GetMapping("/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId){
        log.info("server.port=" + port + ", orderId=" + orderId);
        List<Item> items =itemService.getItems(orderId);
        return JsonResult.ok(items).msg("port="+port);
    }
    @PostMapping("/decreaseNumber")
    public JsonResult decreaseNumber(@RequestBody List<Item> items){
        itemService.decreaseNumbers(items);
        return JsonResult.ok();
    }
}
